﻿using System.Drawing;
using log4net;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NComputerVision.Common;
using NComputerVision.Contour;
using NComputerVision.GraphicsLib;
using NComputerVision.NcvMath;

namespace NComputerVision.Test
{
    [TestClass()]
    public class UtilityTest
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(UtilityTest));

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        [TestMethod()]
        public void DrawVectorField()
        {
            string path = @"d:\3455.jpg";
            Bitmap bmp = new Bitmap(path);
            int[][] mat;
            int width;
            int height;
            ImageConvert.Bitmap2Mat(bmp, out mat, out width, out height);
            GvfSnake gvfSnake = new GvfSnake(mat, 100);
            gvfSnake.InitGVF();

            Complex[,] vf = new Complex[width, height];

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int i = x * height + y;
                    vf[x, y].Re = gvfSnake.px[i];
                    vf[x, y].Im = gvfSnake.py[i];
                }
            }

            Bitmap res = NComputerVision.Common.NcvDrawing.DrawVectorField(vf,width,height);
            res.Save(@"d:\result.jpg");

            log.Info(new NcvMatrix(gvfSnake.px, width, height).ToString());
        }
        
    }
}
